home *** CD-ROM | disk | FTP | other *** search
- /*
- SNEWS 2.0
-
- Mail - routines to mail from news
-
-
- Copyright (C) 1991 John McCombs, Christchurch, NEW ZEALAND
- john@ahuriri.gen.nz
- PO Box 2708, Christchurch, NEW ZEALAND
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 1, as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- See the file COPYING, which contains a copy of the GNU General
- Public License.
-
- Atari version ported by Graham Judd - gjudd@siward.demon.co.uk
- */
-
- /*---------------------------- Source Control ------------------------------*/
-
- /*
- * $Id: MAIL.C,v 1.2 1994/02/05 18:48:42 gbj Exp user $
- */
-
- /****************************************************************************
- * 28 Jun 93 1.01 MSM Initial extraction from article.c *
- * 11 Aug 93 1.02 MSM Expert mode added *
- * 22 Aug 93 1.03 MSM Limited alias support added *
- * 26 Aug 93 1.04 MSM Bug in mailer header detection fixed *
- * 3 Oct 93 1.05 MSM Extra abort options *
- * 24 Oct 93 1.06 MSM Bug in alias handling fixed *
- * 4 Dec 93 1.07 MSM Permit blank organisation *
- * 31 Jan 94 AT1 GBJ News is now posted by nntp in post.c *
- * 2 Apr 94 1.08 MSM Support optional seperator and footer quote *
- ****************************************************************************/
-
-
- #include "defs.h"
- #include "snews.h"
- #include "screen.h"
- #include "locking.h"
-
- #ifdef ATARI
- # include "fileops.h"
- #endif
-
- #include <io.h>
- #include <ctype.h>
-
- long seqno;
-
- extern char marker[];
-
- /*-------------------------- reply to article ---------------------------*/
- void reply_to_article(TEXT * tx, char *subject)
- {
-
- /*
- * Mail reply to article
- */
-
- #ifdef INCLUDE_SIG
- FILE *sig;
- char sig_fn[80];
-
- #endif
-
- FILE *tmp, *new_tmp;
- LINES *ln;
- WRK_FILE *wrk;
- int ch, lct;
- char fn[80];
- char buf[256], buf2[256];
- char author[80], msg_id[80], r_name[128];
- int rc, header;
-
- header = FALSE;
- subject = subject; /* silence warning */
- strcpy(fn, "reply.tmp");
- wrk = NULL;
-
- if ((tmp = fopen(fn, "wt")) != NULL) {
-
- lct = 1;
- get_his_stuff(tx, author, msg_id, r_name);
-
- if (my_stuff.expert == TRUE) {
- if (make_header(tmp, subject, author, NULL, NULL, &lct) != 0) {
- fclose(tmp);
- unlink(fn);
- return;
- }
- }
- else {
- command("");
- sprintf(buf, "Reply to %s (y/n) ", author);
- lmessage(buf);
- do
- {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 'y') && (ch != 'n'));
- if (ch == 'n') {
- lmessage("Reply to whom ? ");
- gets(author);
- }
- }
-
- /* add the quoted message */
- message("Quote article (y/n/a)? ");
- do
- {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 'y') && (ch != 'n') && (ch != 'a'));
- textbackground(msgb);
- textcolor(msgf);
- putch(ch);
- putch('\n');
- putch('\r');
- textbackground(textb);
- textcolor(textf);
-
- if (ch == 'a') {
- fclose(tmp);
- unlink(fn);
- message("*** Mail message aborted - Press any key ***");
- getch();
- return;
- }
- if (ch == 'y') {
- fprintf(tmp, "In article %s you write:\n\n", msg_id);
- if (my_stuff.header_quote)
- ln = tx->top;
- else
- ln = tx->start;
- if (ln->data == '\0')
- ln = ln->next;
- while (ln != NULL) {
- if ((strncmp(ln->data, "-- ", 3) == 0) && my_stuff.footer_quote)
- break;
- fprintf(tmp, "%s%s", my_stuff.quotemark, ln->data);
- ln = ln->next;
- }
- }
- #ifdef INCLUDE_SIG
-
- /* append the signature if there is one */
- strcpy(sig_fn, my_stuff.home);
- strcat(sig_fn, my_stuff.signature);
- if ((sig = fopen(sig_fn, "rt")) != NULL) {
- if (my_stuff.footer_quote)
- fprintf(tmp, "\n-- \n");
- else
- fprintf(tmp, "\n");
- while (fgets(buf, 79, sig) != NULL)
- fputs(buf, tmp);
-
- (void) fclose(sig);
- }
- #endif
- fclose(tmp);
- ch = 'e';
- while ((ch != 's') && (ch != 'a')) {
- if (ch == 'e') {
- sprintf(buf, my_stuff.editor, fn);
- strcpy(buf2, buf);
- if (my_stuff.edit_line != NULL) {
- strcat(buf2, " ");
- if (header == TRUE)
- sprintf(buf, my_stuff.edit_line, lct+1);
- else
- sprintf(buf, my_stuff.edit_line, lct);
- strcat(buf2, buf);
- }
- rc = system(buf2);
- if (rc != 0) {
- unlink(fn);
- return;
- }
- }
-
- if ((my_stuff.expert != TRUE) && (header == FALSE)) {
- if ((tmp = fopen(fn, "r")) == NULL) {
- unlink(fn);
- return;
- }
- if ((new_tmp = fopen("new.tmp", "w+")) == NULL) {
- unlink(fn);
- return;
- }
- if (make_header(new_tmp, subject, author, NULL, NULL, &lct) != 0)
- return;
- while (fgets(buf, sizeof(buf), tmp) != NULL) {
- fputs(buf, new_tmp);
- }
- fclose(tmp);
- fclose(new_tmp);
- unlink(fn);
- rename("new.tmp", fn);
- header = TRUE;
- }
-
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
- printf("Mail reply ?");
- textbackground(textb);
- textcolor(textf);
- sprintf(buf, "(S)end, (A)bort or (E)dit again ? (s/a/e): ");
- message(buf);
- do {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 's') && (ch != 'a') && (ch != 'e'));
- gotoxy(1, scr_rows);
- }
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
- if (ch == 's') {
- wrk = parse(fn, TRUE);
- if (wrk == NULL) {
- unlink(fn);
- message("*** Mail message aborted - Press any key ***");
- getch();
- return;
- }
- pass_to_smtp(fn, wrk, TRUE);
- message("*** Message sent - Press any key ***");
- getch();
- }
- if (ch == 'a') {
- message("*** Mail message aborted - Press any key ***");
- getch();
- }
- unlink(fn);
-
- }
- else {
- message("*** Cannot open temp file - press any key to continue ***");
- getch();
- }
-
- }
-
- /* ---------- (R)eply allowing specified address or alias ---------------- */
-
- void ReplyAddress(TEXT * tx, char *subject)
- {
- #ifdef INCLUDE_SIG
- FILE *sig;
- char sig_fn[80];
-
- #endif
-
- FILE *tmp, *new_tmp;
- WRK_FILE *wrk;
-
- FILE *alias;
- char *s;
-
- LINES *ln;
- int ch, lct;
- char fn[80];
- char buf[256], buf2[256], buf3[24];
- char who_to[1024], author[80], msg_id[80], r_name[128];
- int rc, header;
-
- header = FALSE;
- strcpy(fn, "reply.tmp");
- wrk = NULL;
-
- if ((tmp = fopen(fn, "wt")) != NULL) {
-
- lct = 1;
-
- sprintf(buf, "Send reply to whom: ");
- lmessage(buf);
- gets(who_to);
- if (strlen(who_to) == 0)
- return;
-
- /* look for an alias */
-
- if (strlen(my_stuff.alias_file) != 0) {
- if ((alias = fopen(my_stuff.alias_file, "rt")) != NULL) {
- while (fgets(buf, 255, alias) != NULL) {
- if (buf[0] == ';' || buf[0] == '#' || buf[0] == '\n')
- continue;
- s = strtok(buf, " \t,");
- if (s == NULL)
- continue;
- if (stricmp(who_to, s) == 0) {
- who_to[0] = '\0';
- do
- {
- while ((s = strtok(NULL, " \t,")) != NULL) {
- strcat(who_to, s);
- if (who_to[strlen(who_to)-1] != '\n')
- strcat(who_to, ",");
- else
- who_to[strlen(who_to)-1] = '\0';
- }
- if (fgets(buf, 255, alias) == NULL)
- break;
- if (buf[0] != ' ')
- break;
- s = strtok(buf, " \t");
- if (s != NULL) {
- strcat(who_to, ",");
- strcat(who_to, s);
- if (who_to[strlen(who_to)-1] != '\n')
- strcat(who_to, ",");
- else
- who_to[strlen(who_to)-1] = '\0';
- }
- }
- while (s != NULL);
- }
- }
- fclose(alias);
- }
- }
-
- if (strchr(who_to, '@') == NULL) {
- sprintf(buf, "@%s.%s", my_stuff.my_site, my_stuff.my_domain);
- strcat(who_to, buf);
- }
-
- if (my_stuff.expert == TRUE)
- if (make_header(tmp, subject, who_to, NULL, NULL, &lct) != 0) {
- fclose(tmp);
- unlink(fn);
- return;
- }
-
- get_his_stuff(tx, author, msg_id, r_name);
-
- /* add the quoted message */
- message("Quote article (y/n/a)? ");
- do
- {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 'y') && (ch != 'n') && (ch != 'a'));
- textbackground(msgb);
- textcolor(msgf);
- putch(ch);
- putch('\n');
- putch('\r');
- textbackground(textb);
- textcolor(textf);
-
- if (ch == 'a') {
- fclose(tmp);
- unlink(fn);
- message("*** Mail message aborted - Press any key ***");
- getch();
- return;
- }
- if (ch == 'y') {
- strcpy(buf2, " ");
- strcpy(buf3, " ");
- if ((strlen(msg_id) + strlen(author) + strlen(r_name)) > 60) {
- strcpy(buf2, "\n ");
- if ((strlen(author) + strlen(r_name)) > 60)
- strcpy(buf3, "\n ");
-
- }
- fprintf(tmp, "In article %s%s%s%s%s writes:\n\n", msg_id, buf2, author, buf3, r_name);
- if (my_stuff.header_quote)
- ln = tx->top;
- else
- ln = tx->start;
- if (ln->data == '\0')
- ln = ln->next;
- while (ln != NULL) {
- if ((strncmp(ln->data, "-- ", 3) == 0) && my_stuff.footer_quote)
- break;
- fprintf(tmp, " > %s", ln->data);
- ln = ln->next;
- }
- }
- #ifdef INCLUDE_SIG
- /* append the signature if there is one */
- strcpy(sig_fn, my_stuff.home);
- strcat(sig_fn, my_stuff.signature);
- if ((sig = fopen(sig_fn, "rt")) != NULL) {
- if (my_stuff.footer_quote)
- fprintf(tmp, "\n-- \n");
- else
- fprintf(tmp, "\n");
- while (fgets(buf, 79, sig) != NULL)
- fputs(buf, tmp);
-
- fclose(sig);
- }
- #endif
- fclose(tmp);
-
- ch = 'e';
- while ((ch != 's') && (ch != 'a')) {
- if (ch == 'e') {
- sprintf(buf, my_stuff.editor, fn);
- strcpy(buf2, buf);
- if (my_stuff.edit_line != NULL) {
- strcat(buf2, " ");
- if (header == TRUE)
- sprintf(buf, my_stuff.edit_line, lct+1);
- else
- sprintf(buf, my_stuff.edit_line, lct);
- strcat(buf2, buf);
- }
- rc = system(buf2);
- if (rc != 0) {
- unlink(fn);
- return;
- }
- }
-
- if ((my_stuff.expert != TRUE) && (header == FALSE)) {
- if ((tmp = fopen(fn, "r")) == NULL) {
- unlink(fn);
- return;
- }
- if ((new_tmp = fopen("new.tmp", "w+")) == NULL) {
- unlink(fn);
- return;
- }
- if (make_header(new_tmp, subject, who_to, NULL, NULL, &lct) != 0)
- return;
- while (fgets(buf, sizeof(buf), tmp) != NULL) {
- fputs(buf, new_tmp);
- }
- fclose(tmp);
- fclose(new_tmp);
- unlink(fn);
- rename("new.tmp", fn);
- header = TRUE;
- }
-
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
- printf("Mail article ?");
- textbackground(textb);
- textcolor(textf);
- sprintf(buf, "(S)end, (A)bort, or (E)dit again? (S/A/E):");
- message(buf);
- do {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 's') && (ch != 'a') && (ch != 'e'));
- gotoxy(1, scr_rows);
- }
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
- if (ch == 's') {
- wrk = parse(fn, TRUE);
- if (wrk == NULL) {
- message("*** Mail message aborted - Press any key ***");
- getch();
- unlink(fn);
- return;
- }
- pass_to_smtp(fn, wrk, TRUE);
- message("*** Mail sent - press any key ***");
- getch();
- }
- if (ch == 'a') {
- message("*** Mail message aborted - Press any key ***");
- getch();
- }
-
- unlink(fn);
-
- }
- else {
- message("*** Cannot open temp file - press any key to continue ***");
- getch();
- }
-
- }
-
-
-
-
- /*-------------------------- mail this article ---------------------------*/
- void mail_to_someone(TEXT * tx)
- {
-
- /*
- * Mail this article to someone
- */
-
-
- FILE *tmp, *new_tmp;
- LINES *ln;
- WRK_FILE *wrk;
- int ch, rc, lct, header;
- char fn[80];
- char buf[256], buf2[256], who[1024];
- char subject[80], author[80], msg_id[80], r_name[128];
-
- FILE *alias;
- char *s;
-
- #ifdef INCLUDE_SIG
- FILE *sig;
- char sig_fn[80];
- #endif
-
- header = FALSE;
- strcpy(fn, "reply.tmp");
- wrk = NULL;
-
- if ((tmp = fopen(fn, "wt")) != NULL) {
-
- lct = 1;
-
- if (tx != NULL) {
- get_his_stuff(tx, author, msg_id, r_name);
-
- command("");
- lmessage("To whom do you want to mail this article ? ");
- gets(who);
- if (strlen(who) == 0) {
- fclose(tmp);
- unlink("reply.tmp");
- return;
- }
-
- /* look for an alias */
-
- if (strlen(my_stuff.alias_file) != 0) {
- if ((alias = fopen(my_stuff.alias_file, "rt")) != NULL) {
- while (fgets(buf, 255, alias) != NULL) {
- if (buf[0] == ';' || buf[0] == '#' || buf[0] == '\n')
- continue;
- s = strtok(buf, " \t,");
- if (s == NULL)
- continue;
- if (stricmp(who, s) == 0) {
- who[0] = '\0';
- do
- {
- while ((s = strtok(NULL, " \t,")) != NULL) {
- strcat(who, s);
- if (who[strlen(who)-1] != '\n')
- strcat(who, ",");
- else
- who[strlen(who)-1] = '\0';
- }
- if (fgets(buf, 255, alias) == NULL)
- break;
- if (buf[0] != ' ')
- break;
- s = strtok(buf, " \t");
- if (s != NULL) {
- strcat(who, ",");
- strcat(who, s);
- if (who[strlen(who)-1] != '\n')
- strcat(who, ",");
- else
- who[strlen(who)-1] = '\0';
- }
- }
- while (s != NULL);
- }
-
- }
- fclose(alias);
- }
- }
-
- if (strchr(who, '@') == NULL) {
- sprintf(buf, "@%s.%s", my_stuff.my_site, my_stuff.my_domain);
- strcat(who, buf);
- }
-
- if (my_stuff.expert == TRUE)
- if (make_header(tmp, "Forwarded article.", who, NULL, NULL, &lct) != 0) {
- fclose(tmp);
- unlink("reply.tmp");
- return;
- }
-
- /* add the quoted message */
- fprintf(tmp, "This article was forwarded to you by %s@%s.%s (%s):\n\n",
- my_stuff.user, my_stuff.my_site, my_stuff.my_domain, my_stuff.my_name);
- fprintf(tmp, "--------------------------------- cut here -----------------------------\n\n");
- ln = tx->top;
- while (ln != NULL) {
- fprintf(tmp, "%s", ln->data);
- ln = ln->next;
- }
-
- fprintf(tmp, "--------------------------------- cut here -----------------------------\n\n");
-
- }
- else {
- command("");
- lmessage("Mail to whom ? ");
- gets(who);
- if (strlen(who) == 0) {
- fclose(tmp);
- unlink("reply.tmp");
- return;
- }
- lmessage("Subject ? ");
- gets(subject);
-
- /* look for an alias */
-
- if (strlen(my_stuff.alias_file) != 0) {
- if ((alias = fopen(my_stuff.alias_file, "rt")) != NULL) {
- while (fgets(buf, 255, alias) != NULL) {
- if (buf[0] == ';' || buf[0] == '#' || buf[0] == '\n')
- continue;
- s = strtok(buf, " \t,");
- if (s == NULL)
- continue;
- if (stricmp(who, s) == 0) {
- who[0] = '\0';
- do
- {
- while ((s = strtok(NULL, " \t,")) != NULL) {
- strcat(who, s);
- if (who[strlen(who)-1] != '\n')
- strcat(who, ",");
- else
- who[strlen(who)-1] = '\0';
- }
- if (fgets(buf, 255, alias) == NULL)
- break;
- if (buf[0] != ' ')
- break;
- s = strtok(buf, " \t");
- if (s != NULL) {
- strcat(who, ",");
- strcat(who, s);
- if (who[strlen(who)-1] != '\n')
- strcat(who, ",");
- else
- who[strlen(who)-1] = '\0';
- }
- }
- while (s != NULL);
- }
-
- }
- fclose(alias);
- }
- }
-
- if (strchr(who, '@') == NULL) {
- sprintf(buf, "@%s.%s", my_stuff.my_site, my_stuff.my_domain);
- strcat(who, buf);
- }
-
- if (my_stuff.expert == TRUE )
- if (make_header(tmp, subject, who, NULL, NULL, &lct) != 0) {
- fclose(tmp);
- unlink("reply.tmp");
- return;
- }
-
- #ifdef INCLUDE_SIG
- /* append the signature if there is one */
- strcpy(sig_fn, my_stuff.home);
- strcat(sig_fn, my_stuff.signature);
- if ((sig = fopen(sig_fn, "rt")) != NULL) {
- if (my_stuff.footer_quote)
- fprintf(tmp, "\n-- \n");
- else
- fprintf(tmp, "\n");
- while (fgets(buf, 79, sig) != NULL)
- fputs(buf, tmp);
-
- fclose(sig);
- }
- #endif
-
- }
- fclose(tmp);
-
- ch = 'e';
- while ((ch != 's') && (ch != 'a')) {
- if (ch == 'e') {
- sprintf(buf, my_stuff.editor, fn);
- strcpy(buf2, buf);
- if (my_stuff.edit_line != NULL) {
- strcat(buf2, " ");
- sprintf(buf, my_stuff.edit_line, lct);
- strcat(buf2, buf);
- }
- rc = system(buf2);
- if (rc != 0) {
- unlink(fn);
- return;
- }
- }
-
- if ((my_stuff.expert != TRUE) && (header == FALSE)) {
- if ((tmp = fopen(fn, "r")) == NULL) {
- unlink(fn);
- return;
- }
- if ((new_tmp = fopen("new.tmp", "w+")) == NULL) {
- unlink(fn);
- return;
- }
- if (tx != NULL) {
- if (make_header(new_tmp, "Forwarded Article", who, NULL, NULL, &lct) != 0)
- return;
- }
- else {
- if (make_header(new_tmp, subject, who, NULL, NULL, &lct) != 0)
- return;
- }
- while (fgets(buf, sizeof(buf), tmp) != NULL) {
- fputs(buf, new_tmp);
- }
- fclose(tmp);
- fclose(new_tmp);
- unlink(fn);
- rename("new.tmp", fn);
- header = TRUE;
- }
-
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
- cprintf("Send message ?");
- textbackground(textb);
- textcolor(textf);
- gotoxy(1, scr_rows - 1);
- sprintf(buf, "(S)end, (A)bort or (E)dit again ? (s/a/e):");
- message(buf);
- do
- {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 'a') && (ch != 'e') && (ch != 's'));
- }
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
- if (ch == 's') {
- wrk = parse(fn, TRUE);
- if (wrk == NULL) {
- unlink(fn);
- message("*** Mail message aborted - Press any key ***");
- getch();
- return;
- }
- pass_to_smtp(fn, wrk, TRUE);
- message("*** Mail sent - Press any key ***");
- getch();
- }
-
- if (ch == 'a') {
- message("*** Mail message aborted - Press any key ***");
- getch();
- }
- unlink(fn);
-
- }
- else {
- message("*** Cannot open temp file - press any key to continue ***");
- getch();
- }
- }
-
- /*--------------------- Add a header to the file ---------------------------*/
- int make_header(FILE *tmp, char *subject, char *author, char *cc,
- char *bc, int *lct)
- {
- char buf[256];
- time_t t;
- struct tm *gmt;
- FILE *seq_fp;
-
-
- strcpy(buf, my_stuff.spooldir);
- strcat(buf, "sequence.seq");
- if (mlock(my_stuff.spooldir, "sequence", "Snews") != 0) {
- message("*** Couldn't lock sequence file - press any key ***");
- getch();
- fclose(tmp);
- return -1;
- }
- if ((seq_fp = fopen(buf, "r+")) == NULL) {
- message("*** Couldn't open mail sequence file - press any key ***");
- getch();
- fclose(tmp);
- return -1;
- }
- /* Get the next sequence number */
- rewind(seq_fp);
- fscanf(seq_fp, "%ld", &seqno);
- seqno++;
- rewind(seq_fp);
- fprintf(seq_fp, "%ld\n", seqno);
- fclose(seq_fp);
- rmlock(my_stuff.spooldir, "sequence", "Snews");
- time(&t);
- gmt = gmtime(&t);
- fprintf(tmp, "Date: %s, %02d %s %02d %02d:%02d:%02d GMT\n",
- dow[gmt->tm_wday],
- gmt->tm_mday, mth[gmt->tm_mon], (gmt->tm_year % 100),
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
- (*lct)++;
-
- fprintf(tmp, "Message-ID: <%ld@%s.%s>\n", seqno, my_stuff.my_site,
- my_stuff.my_domain);
- (*lct)++;
- fprintf(tmp, "From: %s@%s.%s (%s)\n", my_stuff.user,
- my_stuff.my_site, my_stuff.my_domain,
- my_stuff.my_name);
- (*lct)++;
- #ifdef ATARI
- if ((my_stuff.my_organisation != NULL) && (*my_stuff.my_organisation != '\0'))
- #else
- if ((*my_stuff.my_organisation != '\0') && (my_stuff.my_organisation != NULL))
- #endif
- fprintf(tmp, "Organization: %s\n", my_stuff.my_organisation);
- else
- fprintf(tmp, "Organization: \n");
- (*lct)++;
- #ifdef ATARI
- if ((my_stuff.replyuser != NULL) && (*my_stuff.replyuser != '\0'))
- #else
- if (*my_stuff.replyuser == '\0')
- #endif
- fprintf(tmp, "Reply-To: %s@%s.%s\n", my_stuff.user,
- my_stuff.my_site, my_stuff.my_domain);
- else
- fprintf(tmp, "Reply-To: %s\n", my_stuff.replyuser);
- (*lct)++;
- fprintf(tmp, "To: %s\n", author);
- (*lct)++;
- if (cc != NULL)
- fprintf(tmp, "Cc: %s\n", cc);
- else
- fprintf(tmp, "Cc: \n");
- (*lct)++;
- if (bc != NULL)
- fprintf(tmp, "Bcc: %s\n", bc);
- else
- fprintf(tmp, "Bcc: \n");
- (*lct)++;
- fprintf(tmp, "Subject: %s\n", subject);
- (*lct)++;
- fprintf(tmp, "X-Mailer: %s\n", VERSION);
- (*lct)++;
- fprintf(tmp, "%s", marker);
- (*lct)++;
- return 0;
- }
-
- /*--------------------- Parse a message for WRK files ----------------------*/
-
- WRK_FILE *parse(char *fname, int ismail)
- {
- WRK_FILE *wrk, *wrk_start;
- FILE *fp, *seq_fp;
- char buff[512], buf2[80], to[80], buf3[80];
- int isto, isfrom, isnewsgps, isid, need_edit;
- int isnottoken, in_header, ch, i;
- char *p, *q;
- long where;
-
- isto = isfrom = isnewsgps = isid = need_edit = FALSE;
- wrk = wrk_start = NULL;
-
- if ((fp = fopen(fname,"rt")) != NULL) {
- do
- {
- need_edit = FALSE;
- in_header = TRUE;
- isnottoken = FALSE;
- while (fgets(buff, 511, fp) != NULL) {
- if (strncmp(buff, marker, 80) == 0) {
- in_header = FALSE;
- break;
- }
- if (in_header == TRUE) {
- if ((strnicmp(buff, "TO:", 3) == 0) && (strlen(buff) > 6))
- isto = TRUE;
- if ((strnicmp(buff, "FROM:", 5) == 0) && (strlen(buff) > 8))
- isfrom = TRUE;
- if ((strnicmp(buff, "MESSAGE-ID:", 11) == 0) && (strlen(buff) > 14))
- isid = TRUE;
- if ((strnicmp(buff, "NEWSGROUPS:", 11) == 0) && (strlen(buff) > 14))
- isnewsgps = TRUE;
- if ((strchr(buff, ':') == NULL) && (buff[0] != ' '))
- isnottoken = TRUE;
- }
- }
-
- if (in_header == TRUE) {
- message("*** End of header not found - press any key ***");
- getch();
- need_edit = TRUE;
- }
- if (isnottoken == TRUE) {
- message("*** Invalid header line found - press any key ***");
- getch();
- need_edit = TRUE;
- }
- if (isto == FALSE) {
- message("*** No 'To:' line in header - press any key ***");
- getch();
- need_edit = TRUE;
- }
- if (isfrom == FALSE) {
- message("*** No 'From:' line in header - press any key ***");
- getch();
- need_edit = TRUE;
- }
- if (isid == FALSE) {
- message("*** No 'Message-ID:' line in header - press any key ***");
- getch();
- need_edit = TRUE;
- }
- if ((isnewsgps == FALSE) && (!ismail)) {
- message("*** No 'Newsgroups:' line in header - press any key ***");
- getch();
- need_edit = TRUE;
- }
- if (need_edit == TRUE) {
- fclose(fp);
- message("(E)dit or (A)bort (e/a) ? ");
- do
- {
- ch = getch();
- ch = tolower(ch);
- }
- while((ch != 'e') && (ch != 'a'));
- if (ch == 'a')
- return NULL;
- sprintf(buff, my_stuff.editor, fname);
- system(buff);
- if ((fp = fopen(fname, "rt")) == NULL) {
- message("*** Unable to open mail file - press any key ***");
- getch();
- return NULL;
- }
- }
- }
- while(need_edit == TRUE);
-
- /* valid open item here */
-
- rewind(fp);
- in_header = TRUE;
- while (fgets(buff, 511, fp) != NULL) {
- if (strncmp(buff, marker, 80) == 0) {
- in_header = FALSE;
- break;
- }
- for (i=0;i<(int)strlen(buff);i++) {
- if (!isspace(buff[i]))
- break;
- in_header = TRUE;
- break;
- }
- where = ftell(fp);
- if (((strnicmp(buff, "TO:", 3) == 0) ||
- (strnicmp(buff, "CC:", 3) == 0) ||
- (strnicmp(buff, "BC:", 3) == 0) ||
- (strnicmp(buff, "BCC:", 4) == 0)) && (in_header == TRUE)) {
- if (strlen(buff) < 6)
- continue;
- if ((strnicmp(buff, "BCC:", 4) == 0) &&(strlen(buff) < 7))
- continue;
- if (strnicmp(buff, "BCC:", 4) == 0)
- strcpy(buf2, buff+5);
- else
- strcpy(buf2, buff+4);
- q = strtok(buf2, " \t\r\n,");
- while (q != '\0') {
- if (wrk_start == NULL) {
- wrk_start = (WRK_FILE *) malloc(sizeof(WRK_FILE));
- wrk = wrk_start;
- wrk->seq = seqno;
- }
- else {
- wrk->next = (WRK_FILE *) malloc(sizeof(WRK_FILE));
- wrk = wrk->next;
- /* get another sequence number */
- strcpy(buf3, my_stuff.spooldir);
- strcat(buf3, "sequence.seq");
- if (mlock(my_stuff.spooldir, "sequence", "Snews") != 0) {
- message("*** Couldn't lock sequence file - press any key ***");
- getch();
- fclose(fp);
- return NULL;
- }
- if ((seq_fp = fopen(buf3, "r+")) == NULL) {
- message("*** Couldn't open mail sequence file - press any key ***");
- getch();
- fclose(fp);
- return NULL;
- }
- /* Get the next sequence number */
- rewind(seq_fp);
- fscanf(seq_fp, "%ld", &seqno);
- seqno++;
- rewind(seq_fp);
- fprintf(seq_fp, "%ld\n", seqno);
- fclose(seq_fp);
- rmlock(my_stuff.spooldir, "sequence", "Snews");
- wrk->seq = seqno;
- }
- wrk->next = NULL;
- p = strchr(q, '@');
- if (p == NULL) {
- sprintf(to, "%s.%s", my_stuff.my_site, my_stuff.my_domain);
- p = to;
- }
- else
- p++;
- strcpy(wrk->next_site, p);
- sprintf(wrk->from, "%s@%s.%s", my_stuff.user, my_stuff.my_site,
- my_stuff.my_domain);
- strcpy(wrk->to, q);
- q = strtok(NULL, " \t\r\n,");
- if (q == NULL) {
- if (fgets(buff, 511, fp) != NULL) {
- if (buff[0] == ' ') {
- strcpy(buf2, buff+1);
- q = strtok(buf2, " \t\n\r,");
- }
- }
- }
- }
- }
- fseek(fp, where, SEEK_SET);
- }
- }
- else
- {
- message("*** Cannot open mail file - press any key to continue ***");
- getch();
- }
-
- fclose(fp);
- return wrk_start;
- }
-
- /*------------------- Pass the mail to the SMTP queue ----------------------*/
- void pass_to_smtp(char *fname, WRK_FILE *wrk, int ismail)
- {
- WRK_FILE *wrk_start, *wrk_ptr;
- FILE *fp, *txtfp, *wrkfp;
- char buff[512], buf2[512];
- char *p;
- int in_header, line_ct;
- time_t t;
- struct tm *gmt;
-
- wrk_start = wrk;
-
- if ((fp = fopen(fname, "r")) != NULL) {
-
- /* Count the lines in the file */
- in_header = TRUE;
- while (fgets(buff, sizeof(buff), fp) != NULL) {
- if ((strncmp(buff, marker, 80) == 0) && (in_header == TRUE)) {
- in_header = FALSE;
- line_ct = 0;
- }
- if (in_header == FALSE)
- line_ct++;
- }
- line_ct--;
-
- while (wrk_start != NULL) {
- if (wrk_start->seq == 0) {
- wrk_start = wrk_start->next;
- continue;
- }
- /* create .txt file */
- sprintf(buff, "%s\\%ld.txt", my_stuff.spooldir, wrk_start->seq);
- if ((txtfp = fopen(buff, "w")) == NULL) {
- message("*** unable to create smtp text file - press any key ***");
- getch();
- free_wrk(wrk);
- return;
- }
- rewind(fp);
- in_header = TRUE;
- while (fgets(buff, sizeof(buff), fp) != NULL) {
- if ((strncmp(buff, marker, 80) == 0) && (in_header == TRUE)) {
- sprintf(buff, "Lines: %d\n\n", line_ct);
- in_header = FALSE;
- }
- if ((strnicmp(buff, "BC:", 3) == 0) && (in_header == TRUE))
- continue;
- if ((strnicmp(buff, "BCC:", 4) == 0) && (in_header == TRUE))
- continue;
- if ((in_header == TRUE) && (buff[0] != ' ')) {
- strcpy(buf2, buff);
- p = strtok(buf2, ":");
- p = strtok(NULL, " \t");
- if (p != NULL)
- if (strcmp(p, "\n") == 0)
- continue;
- }
- fputs(buff, txtfp);
- }
- fclose(txtfp);
- rewind(fp);
- /* create .wrk file */
- sprintf(buff, "%s\\%ld.wrk", my_stuff.spooldir, wrk_start->seq);
- if ((wrkfp = fopen(buff, "w")) == NULL) {
- message("*** unable to create smtp work file - press any key ***");
- getch();
- free_wrk(wrk);
- return;
- }
- fprintf(wrkfp, "%s\n", wrk_start->next_site);
- fprintf(wrkfp, "%s\n", wrk_start->from);
- fprintf(wrkfp, "%s\n", wrk_start->to);
- wrk_start->seq = 0; /* mark entry as processed */
- wrk_ptr = wrk_start;
- while (wrk_ptr->next != NULL) {
- wrk_ptr = wrk_ptr->next;
- if (strcmp(wrk_ptr->next_site, wrk_start->next_site) == 0) {
- fprintf(wrkfp, "%s\n", wrk_ptr->to);
- wrk_ptr->seq = 0;
- }
- }
- fclose(wrkfp);
- wrk_start = wrk_start->next;
- }
-
- /* add the message to the local log */
- txtfp = NULL;
- if (ismail == TRUE) {
- if (stricmp(my_stuff.maillog, "none") != 0) {
- sprintf(buff, "%s%s.txt", my_stuff.mail_dir, my_stuff.maillog);
- if ((txtfp = fopen(buff, "at")) == NULL) {
- message("*** unable to open mail log file - press any key ***");
- getch();
- free_wrk(wrk);
- return;
- }
- }
- }
- else {
- if (stricmp(my_stuff.mailuser, "none") != 0) {
- sprintf(buff, "%s%s.txt", my_stuff.mail_dir, my_stuff.mailuser);
- if ((txtfp = fopen(buff, "at")) == NULL) {
- message("*** unable to open post log file - press any key ***");
- getch();
- free_wrk(wrk);
- return;
- }
- }
- }
- if (txtfp != NULL) {
- rewind(fp);
- in_header = TRUE;
- time(&t);
- gmt = gmtime(&t);
- fprintf(txtfp, "From %s@%s.%s ", my_stuff.user, my_stuff.my_site,
- my_stuff.my_domain);
- fprintf(txtfp, "%s, %02d %s %02d %02d:%02d:%02d GMT\n",
- dow[gmt->tm_wday],
- gmt->tm_mday, mth[gmt->tm_mon], (gmt->tm_year % 100),
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
- while (fgets(buff, sizeof(buff), fp) != NULL) {
- if ((strncmp(buff, marker, 80) == 0) && (in_header == TRUE)) {
- sprintf(buff, "Lines: %d\n\n", line_ct);
- in_header = FALSE;
- }
- fputs(buff, txtfp);
- }
- fprintf(txtfp, "\n");
- fclose(txtfp);
- }
-
- fclose(fp);
- if (ismail == TRUE)
- unlink(fname);
- }
- else{
- message("*** unable to open temporary mail file - press any key ***");
- getch();
- }
- free_wrk(wrk);
- }
-
- /*--------------- Free the memory occupied by the WRK array ----------------*/
- void free_wrk(WRK_FILE*wrk)
- {
-
- WRK_FILE *wrk_start, *wrk_ptr;
-
- wrk_start = wrk;
- while (wrk_start != NULL) {
- wrk_ptr = wrk_start;
- wrk_start = wrk_ptr->next;
- free(wrk_ptr);
- }
- wrk = NULL;
- }
-
-